<template>
	<view class="app">
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>订单号</view>
					<view><input v-model="order_sn" placeholder="请输入支付定单号" /></view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="query">查询</button>
				</view>
			</view>
		</view>
		
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>充值金额</view>
					<view>{{data.amount/100}}元</view>
				</view>
				<view class="flex justify-between inputitem">
					<view>退款金额</view>
					<view class="flex" style="align-items:baseline;">
						<input v-model="data.refund" placeholder="请输入退款金额" />元
					</view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="save">立即退款</button>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	var that,App=getApp(),Comm=getApp().comm;
	export default {
		data() {
			return {
				order_sn:'',
				data:{
					amount:0,
					refund:0
				}
			}
		},
		onLoad() {
			that=this;
		},
		methods: {
			query(){
				this.comm.http('/api/tool/querytxpay',{ordid:this.order_sn}).then(res=>{
					if(res.code==0){
						uni.showToast({icon:'none',title:res.msg});
						return;
					}else{
						this.data={
							amount:res.data.amount.total,
							refund:0
						};
					}
				});
			},
			save(){
				if(!/^\d+$/.test(this.data.refund)){
					uni.showToast({icon:'none',title:'退款金额'});
					return;
				}				
				this.comm.http('/api/tool/refound',{ordid:this.order_sn,allmoney:this.data.amount,amount:this.data.refund}).then(res=>{
					uni.showToast({icon:'none',title:res.msg});
				});
			}
		}
	}
</script>

<style lang="scss">
	.setpidpage{
		.inputitem{
			align-items: center;
			view:nth-child(2){
				flex: 1;margin-left: 8px;
				input{
					height:40px; width: 100%; border-bottom: 1px solid #f0f0f0; font-size: 13px;
				
				}
			}

		}
		.tips{
			font-size: 12px; color: #999; padding: 8px 0; display: block;
		}
	}
</style>
